package com.example.common.enums;

import java.util.HashMap;
import java.util.Map;

/**
 * Description  yes or not 枚举
 *
 * @author hubiao
 * @since 2020-07-29 0:13
 */
public enum YesOrNoEnum {

    NO( 0, "否" ),
    YES( 1, "是" );

    private static Map<Integer, YesOrNoEnum> map = new HashMap<>();

    static {
        for (YesOrNoEnum oneEnum : YesOrNoEnum.values()) {
            map.put( oneEnum.getKey(), oneEnum );
        }
    }

    private Integer key;
    private String value;

    YesOrNoEnum(Integer key, String value) {
        this.key = key;
        this.value = value;
    }

    public static YesOrNoEnum fromKey(Integer key) {
        return map.get( key );
    }

    public static String nameFromKey(Integer key) {
        return map.get( key ).getValue();
    }

    public Integer getKey() {
        return key;
    }

    public Boolean getKeyBoolean() {
        if (YES.key.equals( key )) {
            return true;
        }
        return false;
    }

    public String getValue() {
        return value;
    }
}
